<?php 
	class ControllerMemorySystemsetting extends Controller {
		private $error = array();
		public function index() {
			$this->document->setTitle("systemsetting");
			$this->document->addStyle('admin/view/stylesheet/bootstrap-datetimepicker.min.css');
			$this->document->addScript('admin/view/javascript/bootstrap-datetimepicker.js');
			$this->document->addScript('admin/view/javascript/bootstrap-datetimepicker.zh-CN.js');
			$this->load->model('settingreview/settingreview');
			$this->load->model('setting/setting');
			$reviewtime = $this->model_settingreview_settingreview->getSettingreview($this->session->data['user_id']);
			$label = $this->model_setting_setting->getDefaultLabel($this->session->data['user_id']);
            $data['defaultlabel'] = $label['defaultlabel'];
			foreach ($reviewtime as $key => $value) {
				$index = 'reviewdate'.$value['times'];
				$data[$index] = $value['review_date'];
			}
			$data['maincontent'] = "系统设置";
			$data['sendemailurl'] = $this->url->link('memory/systemsetting/sendTestEmail','',true)."&token=".$this->session->data['token'];
			$data['setdefaultlabelurl'] = $this->url->link('memory/systemsetting/setDefaultLabel','',true)."&token=".$this->session->data['token'];
			$data['edittimeurl'] = $this->url->link('memory/systemsetting/editReviewTime','',true)."&token=".$this->session->data['token'];
			$data['header'] = $this->load->controller('common/headerin');
	 		$data['footerin'] = $this->load->controller('common/footerin');
	 		$data['footer'] = $this->load->controller('common/footer');
	 		$this->response->setOutput($this->load->view('memory/systemsetting', $data));
		}
		public function sendTestEmail(){
            if($this->request->server['REQUEST_METHOD'] == 'POST') {
            	$this->load->library("email");
                $smtpemailto = utf8_strtolower($this->request->post['email']);//发送给谁
				$mailtitle = "测试邮件请勿回复";//邮件主题
				$mailcontent = "如果您成功收到该邮件说明本网站能成功的给您提供的邮箱:".$smtpemailto."发送邮件！<br>该邮件为测试邮件请勿回复。";//邮件内容

				$smtp = new email($smtpemailto,$mailtitle,$mailcontent);
				$state = $smtp->sendemail();
                header('Content-Type:application/json; charset=utf-8');
                exit(json_encode($state,0));
            }
        }
        public function setDefaultLabel(){
        	if($this->request->server['REQUEST_METHOD'] == 'POST') {
            	$this->load->model('setting/setting');
            	$args = array(
            		"label" 	  => $this->request->post['label'],
            		"user_id"     => $this->session->data['user_id']
            		);
                 $state = $this->model_setting_setting->editDefaultLabel($args);
                header('Content-Type:application/json; charset=utf-8');
                exit(json_encode($state,0));
            }
        }
        public function editReviewTime(){
            if($this->request->server['REQUEST_METHOD'] == 'POST') {
            	$this->load->model('settingreview/settingreview');
            	$args = array(
            		"times" 	  => $this->request->post['times'],
            		"review_date" => $this->request->post['review_date'],
            		"user_id"     => $this->session->data['user_id']
            		);
                 $state = $this->model_settingreview_settingreview->editSettingreview($args);
                header('Content-Type:application/json; charset=utf-8');
                exit(json_encode($state,0));
            }
        }
	}
 ?>